package com.imooc.exception;

import com.imooc.utils.IMOOCJSONResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @author mood
 */
@Log4j2
@RestControllerAdvice
public class CustomExceptionHandler {

  /**
   * @Author: MoodAir
   * @Description: 上传文件超过500k，捕获异常：MaxUploadSizeExceededException
   * @Date: 2020/9/22 下午11:25
   * @param: ex
   * @return: com.imooc.utils.IMOOCJSONResult
   * @Version: 1.0
   */
  @ExceptionHandler(MaxUploadSizeExceededException.class)
  public IMOOCJSONResult handlerMaxUploadFile(MaxUploadSizeExceededException ex) {
    log.error(ex);
    return IMOOCJSONResult.errorMsg("文件上传大小不能超过500k，请压缩图片或者降低图片质量再上传！");
  }
}
